#include "selectcpp_s.h"
#ifdef TIME_S_C1_CPP
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <memory.h>
#include <cstring>
#include <ctime>

#include <WinSock2.h>
#include <WS2tcpip.h>
#include <windows.h>

using namespace std;

int main(int argc, char *argv[]){
	WSAData wsaData;
	WSAStartup(MAKEWORD(2, 2), &wsaData);

	SOCKET listenfd, connfd;
	sockaddr_in servaddr;
	char buff[101];
	time_t ticks;

	listenfd = socket(AF_INET, SOCK_STREAM, 0);
	memset(&servaddr, 0, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	servaddr.sin_port = htons(13);

	bind(listenfd, reinterpret_cast<sockaddr*>(&servaddr), sizeof(servaddr));
	listen(listenfd, 10);

	for (;;){
		connfd = accept(listenfd, nullptr, nullptr);
		ticks = time(nullptr);
		sprintf(buff, "%.24s\r\n", ctime(&ticks));
		send(connfd, buff, strlen(buff), 0);
		closesocket(connfd);
	}
	return 0;
}
#endif
